<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
 <head>
  <title>添加活动借用申请</title>
  <t:base type="jquery,easyui,tools,DatePicker"></t:base>
  <script type="text/javascript">
  //编写自定义JS代码
  </script>
 </head>
 <body>
  <t:formvalid formid="formobj" dialog="true" layout="table" action="activityBorrowController.do?addApply" tiptype="1" >
		<input id="id" name="id" type="hidden" value=""> 
		<table style=" " cellpadding="0" cellspacing="1" class="formtable">
				<tr>
					<td align="right">
						<label class="Validform_label">
							学号:
						</label>
					</td>
					<td class="value"> 
						${apply.applyUser.studentNO }
					</td>
				</tr>	
				<tr>
					<td align="right">
						<label class="Validform_label">
							姓名:
						</label>
					</td>
					<td class="value"> 
                	    ${apply.applyUser.realName }

					</td>
				</tr>	
				<tr>
					<td align="right">
						<label class="Validform_label">
							申请时间:
						</label>
					</td>
					<td class="value"> 
                	    <fmt:formatDate value="${apply.applyStartDate }" pattern="yyyy-MM-dd HH:mm"/>至
                        <fmt:formatDate value="${apply.applyEndDate }" pattern="yyyy-MM-dd HH:mm"/>
					</td>
				</tr>	
				<tr>
					<td align="right">
						<label class="Validform_label">
							设备品牌、型号、编号
						</label>
					</td>
					<td class="value" colspan="4">
						  	${apply.device.brand.brandName }、${apply.device.model.modelName }、
						  	${apply.device.deviceNo}
					</td>
			 
				</tr>
				 
			</table>
		</t:formvalid>
		
		<div style="text-align:center;margin-top:20px;">
			<button type="button" id="but_login"  onclick="openScanWindow()" class="btn-big">
                 	 出库
            </button>
 		</div>
 </body>
 <script>
 	  function openScanWindow(){
 		var addurl = 'deviceOutStockController.do?getRfidNo';
 		var api = frameElement.api;
 		$.ajax({
 			url:addurl,
 			async:false,
 			success:function(d){ 
 				
 				if(d == ''){
 					tip('未获取到电子标签信息！');
 					return;
 				}
 				
 				d = $.parseJSON(d);
 				
		    	if(d.id == '${apply.device.id}'){
		    		var retVal = doOutStock();  
		    		if(retVal) {
		    			window.top.optSuccess = true; 
		    			api.close();
		    		}else{
		    			tip('设备出库失败！');
		    		} 
		    	}else{
		    		tip('扫描设备与实际借用设备不匹配');
		    		return false;
		    	}
 			}
 		}); 
 		 
 	  } 
 	  
 	  
 	  /**
 	  *  执行出库操作
 	  */
 	  function doOutStock(){
 		  var  result = true;
 		  $.ajax({
 			  url:'deviceOutStockController.do?appointOutStock&id=${apply.id}',
 			  async:false,
 			  success:function(d){
 				  d = $.parseJSON(d);
 				  result = d.success; 
 				  tip(d.msg);
 			  }
 		  });
 		  
 		  return result;
 	  }
 	  
 </script>
 